home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / P_ROBO31.ZIP / SNIPER.PR < prev    next >
Text File  |  1989-10-23  |  5KB  |  138 lines

  1. (**************************************************************************)
  2. (*                             W A R N I N G                              *)
  3. (*                                                                        *)
  4. (*  This Robot has NOT been designed to take advantage of the advanced    *)
  5. (*  features of P-ROBOTS, such as, Shields, Fuel, Teams or Obstructions.  *)
  6. (**************************************************************************)
  7.  
  8.   PROCEDURE Sniper;
  9.  
  10.     { Sniper is based on a C-Robot by Tom Poindexter }
  11.  
  12.     { Strategy: Since a scan of the entire battlefield can be done in 90 }
  13.     { degrees from a corner, sniper can scan the field quickly. }
  14.  
  15.     { "Global" variables, that can be used by any function or procedure }
  16.   VAR
  17.     corner         : Integer; { current corner 0, 1, 2, or 2 }
  18.     c1x, c1y       : Integer; { corner 1 x and y }
  19.     c2x, c2y       : Integer; {   "    2 "  "  " }
  20.     c3x, c3y       : Integer; {   "    3 "  "  " }
  21.     c4x, c4y       : Integer; {   "    4 "  "  " }
  22.     s1, s2, s3, s4 : Integer; { starting scan position for corner 1 - 4 }
  23.     sc             : Integer; { current scan start }
  24.     d              : Integer; { last damage check }
  25.     closest        : Integer; { check for targets in range }
  26.     Range          : Integer; { range to target }
  27.     dir            : Integer; { scan direction }
  28.  
  29.     { new corner procedure to move to a different corner }
  30.     PROCEDURE new_corner;
  31.  
  32.     VAR
  33.       x, y           : Integer;
  34.       Angle          : Integer;
  35.       New            : Integer;
  36.  
  37.  
  38.     BEGIN
  39.       New := Random(4); { pick a random corner }
  40.       IF (New = corner) THEN { but make it different than the }
  41.         corner := (New+1) MOD 4 { current corner }
  42.       ELSE
  43.         corner := New;
  44.       IF (corner = 0) THEN BEGIN { set new x,y and scan start }
  45.         x := c1x;
  46.         y := c1y;
  47.         sc := s1;
  48.       END;
  49.       IF (corner = 1) THEN BEGIN
  50.         x := c2x;
  51.         y := c2y;
  52.         sc := s2;
  53.       END;
  54.       IF (corner = 2) THEN BEGIN
  55.         x := c3x;
  56.         y := c3y;
  57.         sc := s3;
  58.       END;
  59.       IF (corner = 3) THEN BEGIN
  60.         x := c4x;
  61.         y := c4y;
  62.         sc := s4;
  63.       END;
  64.  
  65.       { find the heading we need to get to the desired corner }
  66.       Angle := Angle_To(x, y);
  67.  
  68.       { start drive train, full speed }
  69.       drive(Angle, 100);
  70.  
  71.       { keep traveling until we are within 150 meters }
  72.       { speed is checked in case we run into wall, other robot }
  73.       { not terribly great, since were are doing nothing while moving }
  74.  
  75.       WHILE ((distance(loc_x, loc_y, x, y) > 150) AND (speed > 0)) DO
  76.         ;
  77.  
  78.       { cut speed, and creep the rest of the way }
  79.  
  80.       drive(Angle, 20);
  81.       WHILE ((distance(loc_x, loc_y, x, y) > 20) AND (speed > 0)) DO
  82.         ;
  83.  
  84.       { stop drive, should coast in the rest of the way }
  85.       drive(Angle, 0);
  86.     END; { end of new_corner }
  87.  
  88.  
  89.   BEGIN {Sniper Main}
  90.  
  91.     { initialize the corner info }
  92.     { x and y location of a corner, and starting scan degree }
  93.     c1x := 10; c1y := 10; s1 := 0;
  94.     c2x := 10; c2y := 990; s2 := 270;
  95.     c3x := 990; c3y := 990; s3 := 180;
  96.     c4x := 990; c4y := 10; s4 := 90;
  97.     closest := 9999;
  98.     new_corner; { start at a random corner }
  99.     d := damage; { get current damage }
  100.     dir := sc; { starting scan direction }
  101.  
  102.     REPEAT {UNTIL DEAD OR WINNER}
  103.  
  104.       WHILE (dir < sc+90) DO BEGIN { scan through 90 degree range }
  105.         Range := scan(dir, 5); { look at a direction }
  106.         IF ((Range <= 700) AND (Range > 0)) THEN BEGIN
  107.           WHILE (Range > 0) DO BEGIN { keep firing while in range }
  108.             closest := Range; { set closest flag }
  109.             cannon(dir, Range); { fire! }
  110.             Range := scan(dir, 5); { check target again }
  111.             IF (d+15 > damage) THEN { sustained several hits, }
  112.               Range := 0; { goto new corner }
  113.           END;
  114.           dir := dir-10; { back up scan, in case }
  115.         END;
  116.  
  117.         dir := dir+10; { increment scan }
  118.         IF (d <> damage) THEN BEGIN { check for damage incurred }
  119.           new_corner; { we're hit, move now }
  120.           d := damage;
  121.           dir := sc;
  122.         END;
  123.       END; { WHILE (dir < sc + 90) -- scan through 90 degree range }
  124.  
  125.       IF (closest = 9999) THEN BEGIN { check for any targets in range }
  126.         new_corner; { nothing, move to new corner }
  127.         d := damage;
  128.         dir := sc;
  129.       END
  130.       ELSE BEGIN { targets in range, resume }
  131.         dir := sc;
  132.         closest := 9999;
  133.       END;
  134.  
  135.     UNTIL Dead OR Winner; {REPEAT}
  136.  
  137.   END; { end of Sniper Main }
  138.